{% extends "layouts/base.volt" %}

{% block title %}{{ get_title() }}{% endblock %}

{% block css %}{{ stylesheet_link('css/pages/signin.css') }}{% endblock %}

{% block content %}
{{ partial("layouts/navbar", ['currentPage': 'signup']) }}

<div class="account-container register">
	
	<div class="content clearfix">
		
		<form action="" method="post">
		
			<h1>马上注册</h1>			
			
			<div class="login-fields">
				
				<p>创建你的账号：</p>
				
				<div class="field">
					<label for="username">用户名：</label>
					<input type="text" id="username" name="username" value="" placeholder="输入用户名" class="login" required="required" />
				</div> <!-- /field -->
				
				<div class="field">
					<label for="email">学号：</label>
					<input type="text" id="student_no" name="student_no" value="" placeholder="输入学号" class="login" required="required"/>
				</div> <!-- /field -->
				
				<div class="field">
					<label for="password">密码：</label>
					<input type="password" id="password" name="password" value="" placeholder="输入密码" class="login" required="required"/>
				</div> <!-- /field -->
				
				<div class="field">
					<label for="confirm_password">确认密码：</label>
					<input type="password" id="confirm_password" name="confirm_password" value="" placeholder="确认密码" class="login" required="required"/>
				</div> <!-- /field -->
				
			</div> <!-- /login-fields -->
			<div id="alert">
			</div>

			<div class="login-actions">
				
				<span class="login-checkbox">
					<input id="Field" name="Field" type="checkbox" class="field login-checkbox" value="First Choice" tabindex="4" />
					<label class="choice" for="Field">自觉认同平台协议。</label>
				</span>
									
				<!--<button id="signup_button" class="button btn btn-primary btn-large" type="">注册</button>-->
				<input id="signup_button" class="button btn btn-primary btn-large" type="button" value="注册">

				
			</div> <!-- .actions -->
			
		</form>
		
	</div> <!-- /content -->
	
</div> <!-- /account-container -->


<!-- Text Under Box -->
<div class="login-extra">
	已经有账号?？<a href="login">登陆到你的账号</a>
</div> <!-- /login-extra -->
{% endblock %}

{% block js %}
<script>
$(document).ready(function(){
  $("#signup_button").click(function() {
    var username = $("#username").val();
    var password = $("#password").val();
    var confirm_password = $("#confirm_password").val();
    var student_no = $("#student_no").val();
    if(password != confirm_password) {
    	alert("密码不一致");
    	return;
    }
    $.post("/signup/signup",
    {
      username:username,
      password:password,
      student_no:student_no
    },
    function(data,status){
      if(data == "success"){
        //alert("成功注册");
        $("#alert").html("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>恭喜！</strong> 成功注册。</div>");
        top.location = "/login";
      }else{
      	if(data.indexOf("student_no") > 0){
      	  //alert("学号已经被关联");
      	  $("#alert").html("<div class='alert'><button type='button' class='close' data-dismiss='alert'>×</button><strong>警告！</strong> 学号已经被关联。</div>");
      	}else if(data.indexOf("name") > 0){
      	  //alert("用户名已经被注册");
      	  $("#alert").html("<div class='alert'><button type='button' class='close' data-dismiss='alert'>×</button><strong>警告！</strong> 用户名已经被注册。</div>");
      	}else{
      	  //alert(data);
      	  $("#alert").html("<div class='alert'><button type='button' class='close' data-dismiss='alert'>×</button><strong>警告！</strong> 非法操作。</div>");
      	}
      }
    });
  });
});
</script>
{% endblock %}